package com.shuang.config;

import com.shuang.pojo.Person;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import sun.misc.IOUtils;
import sun.nio.ch.IOUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.util.Scanner;

/**
 * @DATE: 2021/09/26 17:00
 * @Author: 小爽帅到拖网速
 */
@Slf4j
@Component
@CrossOrigin
public class CheckHandlerInterceptor implements HandlerInterceptor {

  @Override
  public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

    Scanner scanner = new Scanner(System.in);
    System.out.println("健康码-key y/n:");
    String flag = scanner.next();
    if (flag.equals("y")){
      request.getSession().setAttribute("flag",flag);
      System.out.println("AOP拦截成功 y");
      return true;
    }else {
      System.out.println("AOP拦截成功 n");
      return false;
    }

  }

  @Override
  public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

  }

  @Override
  public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

  }
}
